class Message{

    static msgType = {
        'authorization': 'authorization',
        'join': 'join',
        'notification': 'notification',
        'getRouterCapabilities': 'getRouterCapabilities',
        'createTransport':'createTransport',
        'transport-connect': 'transport-connect',
        'producer': 'producer',
        'produceData': 'produceData',
        'connectWebRtcTransport': 'connectWebRtcTransport',
        'newConsumer': 'newConsumer',
        'consumeData' : 'consumeData',
        'memberDestroy': 'memberDestroy',
        'pauseProducer': 'pauseProducer',
        'pauseConsumer': 'pauseConsumer',
        'resumeProducer': 'resumeProducer',
        'resumeConsumer': 'resumeConsumer',
        'ping': 'ping',
        'pong': 'pong',
        'statistics': 'statistics'
    }



    static decoder(message) {
        const decoder = {}
        try{
            const data = JSON.parse(message);
            decoder.type = data["type"]
            decoder.data = data["data"]
        }catch (e) {
            console.log('message', e)
            decoder.type = 'error'
            decoder.data = e.toString()
        }
        // console.log('recv', decoder)
        return decoder
    }

    static encoder(type, data){
        // console.log('send', {
        //     type,
        //     data
        // })
        return JSON.stringify({
            type,
            data
        })
    }


}
export default Message
